﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Evoucher.Business.Models;
using System.Web;

namespace Evoucher.Business.Logging
{
    public static class Logger
    {
        public static void LogEvent(string message, string username)
        {
            evoucherEntities repo = new evoucherEntities();
            Log log = new Log();
            log.Description = message;
            log.IpAddress = HttpContext.Current.Request.UserHostAddress;
            log.LogTime = DateTime.Now;

            if ( HttpContext.Current.Request.UrlReferrer != null )
                log.ReferrerUrl = HttpContext.Current.Request.UrlReferrer.ToString();

            log.UserAgent = HttpContext.Current.Request.UserAgent;
            log.UserName = username;
            repo.AddToLogs(log);
            repo.SaveChanges();
        }
    }
}
